/*
 * @Date: 2020-10-06 14:42:36
 * @Author: David
 * @LastEditors: OBKoro1
 * @LastEditTime: 2020-10-06 21:46:53
 * @FilePath: /huanyong-task-01-01/code/testpromise.js
 * @Description: someting...
 */
import MyPromise from './myPromise'
// 1. 调用 then 
new MyPromise( function (resolve,reject) {
    resolve('success')
    //reject('error')
}).then(res => {
    console.log('1： 成功回调',res);
},err => {
    console.log('失败原因:',err)
})
// 2. 调用 then 
new MyPromise( function (resolve,reject) {
    //resolve('success')
    reject('fail')
}).then(undefined,err => {
    console.log('2: 失败回调:',err)
})
// 3. 延时回调 
new MyPromise( function (resolve,reject) {
    setTimeout(() => {
        resolve('延时回调')
    },20)
}).then(res => {
    console.log('3: 延时回调:',res)
})
// 4. catch 
new MyPromise( function (resolve,reject) {
    setTimeout(() => {
        reject('catch error')
    },30)
}).catch(err => {
    console.log('4: catch:',err)
})
// 5. finally 
new MyPromise( function (resolve,reject) {
    setTimeout(() => {
        resolve('finally')
    },40)
}).finally(() => {
    console.log('5. finally:')
})
// 6. all 
Promise.all(['1','2',new Promise((resolve) => {
    setTimeout(() => {
        resolve('3')
    },100)
})]).then(res => {
    console.log('6.Promise.all',res)
})
// 7. race 
setTimeout(() => {
    Promise.race(['1','2',new Promise((resolve) => {
        resolve('3')
    })]).then(res => {
        console.log('7.Promise.race',res)
    })
},200)

// 8. allSettled 
Promise.allSettled(['1','2',new Promise((resolve) => {
    setTimeout(() => {
        resolve('3')
    },300)
})]).then(res => {
    console.log('8.Promise.allSettled',res)
})
